{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.6a1fd616ed6cad3ce2be6102bbc59610.315360000.1926689036.282335-23575562', 'expires_in': 2592000, 'session_key': '9mzdCKXj74BcVx0UxTfykOD/TAqYkfQNCJpVZXvE06HplfUbkt1CQSqZX92+euhi4DI5ruGYAeZ5QrkFQ+A1yyrcCmsWjw==', 'access_token': '24.3abd95466f7aa69a1d3b18f517fb7fe2.2592000.1613921036.282335-23575562', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin', 'session_secret': 'bce0fc3ee061111d45f5ba59cce3e852'}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>refresh_token</th>\n",
       "      <td>25.6a1fd616ed6cad3ce2be6102bbc59610.315360000....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>expires_in</th>\n",
       "      <td>2592000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>session_key</th>\n",
       "      <td>9mzdCKXj74BcVx0UxTfykOD/TAqYkfQNCJpVZXvE06Hplf...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>access_token</th>\n",
       "      <td>24.3abd95466f7aa69a1d3b18f517fb7fe2.2592000.16...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>scope</th>\n",
       "      <td>public vis-classify_dishes vis-classify_car br...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>session_secret</th>\n",
       "      <td>bce0fc3ee061111d45f5ba59cce3e852</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                                0\n",
       "refresh_token   25.6a1fd616ed6cad3ce2be6102bbc59610.315360000....\n",
       "expires_in                                                2592000\n",
       "session_key     9mzdCKXj74BcVx0UxTfykOD/TAqYkfQNCJpVZXvE06Hplf...\n",
       "access_token    24.3abd95466f7aa69a1d3b18f517fb7fe2.2592000.16...\n",
       "scope           public vis-classify_dishes vis-classify_car br...\n",
       "session_secret                   bce0fc3ee061111d45f5ba59cce3e852"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "import pandas as pd\n",
    "import json\n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=WmoAqK4R5PiyTTBe37SYCLzA&client_secret=h7rcG9Gu5sT6rCLZjzVxImc1IL2wumGR'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())\n",
    "pd.json_normalize(response.json()).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.3abd95466f7aa69a1d3b18f517fb7fe2.2592000.1613921036.282335-23575562'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "access_token = response.json()[\"access_token\"]\n",
    "access_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 384381582882584118, 'result': [{'score': 0.8253432512283325, 'name': '圆锥石头花'}, {'score': 0.030936693772673607, 'name': '满天星'}, {'score': 0.005403541028499603, 'name': '勿忘我'}]}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "植物识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/plant\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('C:/Users/86133/Desktop/a.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.711516bff82010c4b8d3c958758aa025.2592000.1613895477.282335-23575562'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 6873023172494564758, 'result_num': 5, 'result': [{'score': 0.851997, 'root': '商品-农用物资', 'keyword': '花卉'}, {'score': 0.656376, 'root': '植物-其它', 'keyword': '满天星'}, {'score': 0.481185, 'root': '植物-花束', 'keyword': '仿真花'}, {'score': 0.302251, 'root': '商品-花束', 'keyword': '干花花束'}, {'score': 0.125238, 'root': '植物-其它', 'keyword': '仿真花卉'}]}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "通用物体和场景识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('C:/Users/86133/Desktop/a.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.711516bff82010c4b8d3c958758aa025.2592000.1613895477.282335-23575562'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
